package com.hilihili.controller.uploadController;
import java.io.IOException;

import com.hilihili.domain.dto.DeleteTempFileDTO;
import com.hilihili.domain.dto.ImageUploadDTO;
import com.hilihili.domain.dto.VideoSubmitDTO;
import com.hilihili.domain.dto.VideoUploadDTO;


import com.hilihili.service.IVideoService;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * 视频上传
 *
 * @author machi
 * @date 2023/12/16
 */

@RestController
@RequestMapping("hilihili/upload")
public class UploadController {


    @Autowired
    IVideoService videoService;

    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody VideoSubmitDTO videoSubmitDTO){
        try {
            return videoService.insertVideo(videoSubmitDTO);
        } catch (IOException e) {
            return AjaxResult.error(500, "服务器异常");
        }
    }

    @PostMapping()
    public ResponseEntity uploadVideo(VideoUploadDTO videoUploadDTO) throws IOException {
        ResponseEntity responseEntity;
        try {
            responseEntity = videoService.uploadVideo(videoUploadDTO);
        }catch (InterruptedException exception){
            return ResponseEntity.status(500).body("服务器异常");
        }
        return responseEntity;
    }
    @PostMapping("/image")
    public ResponseEntity uploadVideo(ImageUploadDTO imageUploadDTO) {
        return videoService.uploadImage(imageUploadDTO);
    }

    /**
     * 用户取消上传文件
     * @param deleteTempFileDTO
     * @return {@link AjaxResult}
     */
    @DeleteMapping("/delete")
    public AjaxResult deleteVideo(@RequestBody DeleteTempFileDTO deleteTempFileDTO)  {

        return videoService.deleteTempVideoById(deleteTempFileDTO);
    }




}


